package com.suoluo.zenadmin.controllers.mobile;

import java.util.List;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.service.dest.DestFeatureCategoryService;
import com.suoluo.zenadmin.service.dest.MobileService;
import com.suoluo.zenadmin.vo.classify.FeatureItemVO;
import com.suoluo.zenadmin.vo.classify.HomeStyleVO;
import com.suoluo.zenadmin.vo.dest.DestFeatureCategoryVO;
import com.suoluo.zenadmin.vo.home.HomeItemPortalVO;


/**
 * 手机版的首页，导航页的的action
 * @author xiongxu
 *
 */
@Path("")
public class MobileHomeController {
	@Resource(name = "mobileService")
	private MobileService mobileService;

	@Resource(name="categoryService")
	private DestFeatureCategoryService categoryService;
	/**
	 * 查询导航页特色分类信息
	 * @param request
	 * @param response
	 * @return
	 */
	@Get({"","home.do"})
	public String get(Invocation inv,@Param("action") String action,@Param("pageNum") int pageNum)
	{
		if ("navigate".equals(action)){
			return navigate(inv);
		}else if ("home".equals(action)){
			return home(inv,pageNum);
		}else if ("listFeatureItems".equals(action)){
			return listFeatureItems(inv, pageNum);
		}else if ("homeStyle".equals(action)){
			return homeStyle(inv);
		}
		return home(inv,pageNum);
	}
	@Post({"","home.do"})
	public String post(Invocation inv,@Param("action") String action,@Param("pageNum") int pageNum){
		return get(inv, action, pageNum);
	}
	/**
	 * 在导航页点击首页，跳转到首页页面，该页面主要显示勾选的首页特色类别项数据
	 * @param request
	 * @param response
	 * @return
	 */
	public String home(Invocation inv,int pageNum)
	{
		if (pageNum == 0){
			pageNum = 1;
		}
		List<HomeItemPortalVO> list = mobileService.findAllHomeData(pageNum);
		inv.addModel("homeData",list);
		int nextPage = mobileService.findHomeNextPage(pageNum);
		inv.addModel("nextPage",nextPage);
		return "home";
	}

	private String navigate(Invocation inv){
		List<DestFeatureCategoryVO> list = categoryService.findRootCategoryWithoutHotel();
		inv.addModel("categoryList",list);
		return "navigate";
	}
	/**
	 * 点击导航页中的特色类别，调此方法查看该类别的特色项信息
	 * action=listFeatureItems&pageNum=1&featureCategoryId=5
	 * @param request
	 * @param response
	 */
	private String listFeatureItems(Invocation inv,int pageNum)
	{
		if (pageNum == 0){
			pageNum = 1;
		}
		int featureCategoryId = Integer.parseInt(inv.getParameter("featureCategoryId"));
		
		DestFeatureCategoryVO category = categoryService.findDestFeatureCategoryById(featureCategoryId);
		inv.addModel("category", category);
		List<FeatureItemVO> list = mobileService.findFeatureItemByCategoryId(featureCategoryId, pageNum);
		int nextPage = mobileService.findNextFeatureItemPage(featureCategoryId, pageNum);
		inv.addModel("nextPage",nextPage);
		//统计总的特色项信息
		inv.addModel("itemList",list);
		return "dest/listFeatureItem";
	}

	

	/**
	 * 风格偏好的首页类别信息
	 * @param request
	 * @param response
	 * @return
	 */
	public String homeStyle(Invocation inv)
	{
		List<HomeStyleVO> list = mobileService.findHomeStyleItems();
		inv.addModel("styleHomeList",list);
		return "style/styleHome";
	}

}
